package com.qst.crop.service.impl;

import com.qst.crop.entity.Finance;
import com.qst.crop.entity.Intention;
import com.qst.crop.model.Recommend;
import com.qst.crop.dao.FinanceDao;
import com.qst.crop.service.FinanceService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import java.util.List;

import jakarta.annotation.Resource;

/**
 * (Finance)表服务实现类
 *
 * @author Wlj
 * @since 2025-09-02 15:28:21
 */
@Service("financeService")
public class FinanceServiceImpl implements FinanceService {
    @Resource
    private FinanceDao financeDao;

    /**
     * 通过ID查询单条数据
     *
     * @param financeId 主键
     * @return 实例对象
     */
    @Override
    public Finance queryById(Integer financeId) {
        return this.financeDao.queryById(financeId);
    }

    /**
     * 分页查询
     *
     * @param finance 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<Finance> queryByPage(Finance finance, PageRequest pageRequest) {
        long total = this.financeDao.count(finance);
        return new PageImpl<>(this.financeDao.queryAllByLimit(finance, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param finance 实例对象
     * @return 实例对象
     */
    @Override
    public Finance insert(Finance finance) {
        this.financeDao.insert(finance);
        return finance;
    }

    /**
     * 修改数据
     *
     * @param finance 实例对象
     * @return 实例对象
     */
    @Override
    public Finance update(Finance finance) {
        this.financeDao.update(finance);
        return this.queryById(finance.getFinanceId());
    }

    /**
     * 通过主键删除数据
     *
     * @param financeId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer financeId) {
        return this.financeDao.deleteById(financeId) > 0;
    }

    // ===== 融资意向与推荐 =====
    @Override
    public Intention selectIntentionByName(String name) {
        return this.financeDao.selectIntentionByName(name);
    }

    @Override
    public int updateIntentionByName(Intention intention) {
        return this.financeDao.updateIntentionByName(intention);
    }

    @Override
    public int insertIntentionByName(Intention intention) {
        return this.financeDao.insertIntentionByName(intention);
    }

    @Override
    public List<Recommend> selectWithNoneIntention(String name) {
        return this.financeDao.selectWithNoneIntention(name);
    }

    @Override
    public List<Recommend> selectAllRecommend(String name) {
        return this.financeDao.selectAllRecommend(name);
    }

    @Override
    public List<Finance> selectByName(String ownName) {
        return this.financeDao.selectByName(ownName);
    }
}
